package com.lyt.springboot.util.algorithm;

public class Solution {
    public static void main(String[] args) {
        Solution s = new Solution();
        String a = "1.2.3.4";
        String[] aa = a.split("\\.");

        String b = "1.2.3.1.1";
        int result = s.compare("1.2.3.4", "1.2.3.4");
        System.out.println(result);

    }
    public int compare(String version1 ,String version2) {
        String[] v1 = version1.split("\\.");
        String[] v2 = version2.split("\\.");
        int n = Math.max(v1.length, v2.length);

        int[] k1 = new int[n];
        int[] k2 = new int[n];

        for (int i = 0; i < v1.length; i++) {
            k1[i] = Integer.valueOf(v1[i]);
        }
        for (int i = 0; i < v2.length; i++) {
            k2[i] = Integer.valueOf(v2[i]);
        }
        for (int i = 0; i < n; i++) {
            if(k1[i]>k2[i]) {
               return 1;
            }else if(k1[i]<k2[i]) {
                return -1;
            }
        }
        return 0;
    }

}
